Implement topological_sort_levels#501
Conversation
It's not a foul, and it is important to note, so thank you. |
|
Could you please go into more detail on:
Thanks, cheers. |
|
Thank you @joemalle for the PR and @jeremy-murphy for the comment. Feel free to edit your own PR first message 😄 |
|
Compiler-warning counts vs
|
|
Note 1 : the +6 warnings on msvc are not an error of the test or header, it's due to Boost.PropertyMap lib forcing a Note 2 Boost.PropertyMap was community maitained, I jumped in but the CI is on fire, we should not condition the present |
|
Hi, I'm happy to contribute! And thank you for investigating/fixing those warnings. Here are some answers. I can edit the main description when we have a finalized design.
Sorting into "levels" or "generations" is a common issue in scheduling. You find yourself with a DAG of jobs, and you want to know which ones can run concurrently. I faced a similar scheduling-related issue when I posted this three years ago. I wanted to find sets of instructions that could be reordered/vectorized without affecting correctness. While writing this answer, I learned that toposorting into levels can also be useful when drawing layered graphs e.g. when rendering DOT/graphviz files.
We absolutely could enhance the existing DFS implementation. I'm happy to switch to that if you prefer. However, we'd have to add more branches and a small amount of extra state to track the depth. This BFS algorithm is, in my opinion, more natural since it naturally iterates through levels. This is mentioned in the commit, but just in case, this is Kahn's algorithm (https://en.wikipedia.org/wiki/Topological_sorting#Kahn's_algorithm). |
This phab implements issue #240 . Please note that I'm not a frequent contributor, and I may have made some noob mistakes. Also, I used Claude to write this. LMK if that's a foul.
Before submitting
developbranch.Type of change
Does this PR introduce a breaking change?
What this PR does
Adds functions to toposort into levels. There's a lower level function that uses a property map to output the vertex levels and a vector shorthand.
Motivation
Fixes issue #240
Testing
I added new tests. Here's what I ran
Checklist
b2in thetest/directory).